home *** CD-ROM | disk | FTP | other *** search
-
- {$A+} { Align data }
- {$B-} { Boolean evaluation }
- {$D-} { Debug information }
- {$F-} { Force FAR calls }
- {$G+} { 80286 code }
- {$I-} { I/O checking }
- {$K-} { Smart Callbacks }
- {$L+} { Local symbols }
- {$N-} { 80x87 code }
- {$O-} { Overlays allowed }
- {$P-} { Open parameters }
- {$R-} { Range checking }
- {$S-} { Stack checking }
- {$Q-} { Overflow checking }
- {$T-} { Typed @ operators }
- {$V-} { String VAR checking }
- {$W-} { Windows stack frame for real mode }
- {$X+} { Extended syntax }
- {$Y+} { Symbol reference information }
-
- {$M 4096,4096}
-
- { This is a Pascal version of the C program MUSTEST.C from the MS
- Developer's Network CD Fall/92. Doesn't do anything useful, just
- shows how to use the Spin Buttons implemented in MUSCROLL.DLL.
-
- If you find any bugs please let me know.
- Olaf He▀ (Hess), Munich, Germany.
- CompuServe ID: 100 031, 35 36
- }
-
- PROGRAM MiniScrollTest;
-
- {$R MUSTEST.RES}
-
- USES WinTypes, WinProcs, OWindows, ODialogs, MuScroll;
-
- CONST
- id_Edit1 = 101;
- id_Edit2 = 102;
- id_VertScroll = 201;
- id_HorizScroll = 202;
-
- TYPE
- TMiniApp = OBJECT (TApplication)
- PROCEDURE InitMainWindow; VIRTUAL;
- END; { TMiniApp }
-
- PTestDlg = ^TTestDlg;
- TTestDlg = OBJECT (TDlgWindow)
- pToEdit1, pToEdit2 : PEdit;
- hVertScroll, hHorizScroll : hWnd;
-
- CONSTRUCTOR Init (AParent: PWindowsObject; AName: PChar);
- PROCEDURE SetupWindow; VIRTUAL;
-
- PROCEDURE wmVScroll (VAR Msg: TMessage);
- VIRTUAL wm_First + wm_VScroll;
- PROCEDURE wmHScroll (VAR Msg: TMessage);
- VIRTUAL wm_First + wm_HScroll;
- END; { TTestDlg }
-
- (* ---- *)
-
- PROCEDURE TMiniApp.InitMainWindow;
- { Initialize window object }
-
- BEGIN
- MainWindow := New (PTestDlg, Init (NIL, 'TestDialog'));
- END; { TMiniApp.InitMainWindow }
-
- (* ---- *)
-
- CONSTRUCTOR TTestDlg.Init (AParent: PWindowsObject; AName: PChar);
- { Set up the dialogbox }
-
- BEGIN
- Inherited Init (AParent, AName); { Call ancestor }
-
- { Create control object for edit control }
- New (pToEdit1, InitResource (@SELF, id_Edit1, 3));
- New (pToEdit2, InitResource (@SELF, id_Edit2, 30));
- END; { TTestDlg.Init }
-
- (* ---- *)
-
- PROCEDURE TTestDlg.SetupWindow;
- { Initialize controls }
-
- BEGIN
- Inherited SetupWindow;
-
- { Insert number into the edit controls }
- pToEdit1^.Insert ('50');
- pToEdit2^.Insert ('Horizontal Edit Control');
-
- { Get hWnd of controls }
- hVertScroll := GetDlgItem (hWindow, id_VertScroll);
- hHorizScroll := GetDlgItem (hWindow, id_HorizScroll);
-
- { Set the range of the horizontal spin button }
- SendMessage (hVertScroll, msm_dwRangeSet, 0, MakeLong (1, 99));
- SendMessage (hVertScroll, msm_wCurrentPosSet, 50, 0);
-
- { Change the colors of the vertical spin button }
- MSCrColorSet (hHorizScroll, MSColor_Face, RGB (0, 0, 255));
- MSCrColorSet (hHorizScroll, MSColor_Arrow, RGB (255, 255, 255));
- MSCrColorSet (hHorizScroll, MSColor_Shadow, RGB (0, 0, 128));
- MSCrColorSet (hHorizScroll, MSColor_HighLight, RGB (0, 255, 255));
- END; { TTestDlg.SetupWindow }
-
- (* ---- *)
-
- PROCEDURE TTestDlg.wmVScroll (VAR Msg: TMessage);
- { One of the thumb-buttons of the vertical spin button control has been
- pressed }
-
- VAR
- wPos, wMax, wMin, wNum : Word;
- lRange : LongInt;
- fIsValid : bool;
- szNum : ARRAY [0..2] OF Char;
- awDummy : ARRAY [1..1] OF Word;
-
- BEGIN
- SetFocus (pToEdit1^.hWindow); { Set focus on edit control }
-
- WITH Msg DO
- IF (lParamHi = hVertScroll) THEN
- BEGIN { lParamHi = the hWindow of the mini scroll,
- not the control id! }
-
- { Ignore what comes from MSM_WCurrentPosSet -- See MUSTEST.C }
- IF (wParam = sb_ThumbTrack) THEN Exit;
-
- wPos := lParamLo; { Get current spin button value }
-
- { Get minimum & maximum values allowed }
- lRange := SendMessage (hVertScroll, msm_dwRangeGet, 0, 0);
- wMax := HiWord (lRange);
- wMin := LoWord (lRange);
-
- { Get the edit control's content }
- wNum := GetDlgItemInt (hWindow, id_Edit1, @fIsValid, TRUE);
-
- { Check if we got a valid value from the control. Otherwise
- use the current value. }
- IF (fIsValid) AND (wNum >= wMin) THEN
- BEGIN
- { If we are decrementing the value and (wNum - 1) = wPos,
- then we don't need TO modify anything. Otherwise, wPos
- must become wNum - 1 IF that is >= minimum. }
-
- { Down arrow pressed }
- IF (wParam = sb_LineDown) AND ((wNum - 1) <> wPos) THEN
- IF (wNum > wMin) THEN wPos := wNum - 1
- ELSE wPos := wMin;
-
- { Up arrow pressed }
- IF (wParam = sb_LineUp) AND ((wNum + 1) <> wPos) THEN
- IF (wNum < wMax) THEN wPos := wNum + 1
- ELSE wPos := wMax;
- END; { if }
-
- IF (wPos <> wNum) THEN
- BEGIN { Only change the control if we have to. }
- awDummy [1] := wPos;
- wvsprintf (szNum, '%d', awDummy);
- pToEdit1^.SetText (szNum);
- END; { if }
-
- { Update the current position if it changed }
- IF (wPos <> lParamLo) THEN
- SendMessage (hVertScroll, msm_wCurrentPosSet, wNum, 0);
-
- { We always want to do this is case the user typed something but
- we could not scroll (like he typed in the max), in which
- case the selection went away. }
- SendMessage (pToEdit1^.hWindow, em_SetSel, 0,
- MakeLong (0, 32727));
-
- Result := 0;
- Exit;
- END; { if }
-
- DefWndProc (Msg);
- END; { TTestDlg.wmVScroll }
-
- (* ---- *)
-
- PROCEDURE TTestDlg.wmHScroll (VAR Msg: TMessage);
- { One of the thumb-buttons of the vertical spin button control has been
- pressed }
-
- VAR
- lPos : LongInt;
- wPos : Word;
-
- BEGIN
- SetFocus (pToEdit2^.hWindow); { Set focus on edit control }
-
- WITH Msg DO
- IF (lParamHi = hHorizScroll) THEN
- BEGIN
- { Get selection }
- lPos := SendMessage (pToEdit2^.hWindow, em_GetSel, 0, 0);
- wPos := LoWord (lPos); { Starting point }
-
- { Left or right button pressed? }
- IF (wParam = sb_LineUp) THEN
- BEGIN { Right }
- Dec (wPos);
- IF (wPos < 0) THEN wPos := 0;
- END { if }
- ELSE
- BEGIN { Left }
- Inc (wPos);
- IF (wPos > 32767) THEN wPos := 32767;
- END; { else }
-
- lPos := MakeLong (wPos, wPos); { Set new position }
- SendMessage (pToEdit2^.hWindow, em_SetSel, 0, lPos);
- END { if }
- ELSE DefWndProc (Msg);
- END; { TTestDlg.wmHScroll }
-
- (* ---- *)
-
- { Main program }
-
- VAR
- MiniApp : TMiniApp;
-
- BEGIN { MiniScrollTest }
- WITH MiniApp DO
- BEGIN
- Init (NIL);
- Run;
- Done;
- END; { with }
- END. { MiniScrollTest }
-